<layout name="page" />
<block name="content">
	<input type="hidden" name="ajax" id="ajax" value="1">
	{:widget('page_header/simple',array('name'=>$folder_name))}
	<div class="operate-panel">
		<div class="split"></div>
		<a onclick="add()" class="btn x-click" data-fun="add">新增</a>
		<a id="btn_save" class="btn x-click" data-fun="save">保存</a>
		<span class="l">|</span>
		<a onclick="del()"class="btn btn-del x-click" data-fun="del">删除</a>
	</div>
	<div class="sub-frame">
		<div class="sub-sidebar gray ">
			<?php echo $menu ?>
		</div>
		<div class="sub-content gray">
			<form id="form_data" name="form_data" method="post" >
				<input type="hidden" name="id" id="id">
				<input type="hidden" name="opmode" id="opmode" value="">
				<select name="folder_list" id="folder_list" class="hidden">
					{:fill_option($folder_list)}
				</select>
				<div class="layui-sub-form-item">
					<label class="input-label" for="name">名称*：</label>
					
						<input class="input" type="text" id="name" name="name" info="请输入名称">
					</div>
				</div>
				<div class="layui-sub-form-item">
					<label class="input-label" for="sort">排序：</label>
					
						<input class="input" type="text" id="sort" name="sort" >
					</div>
				</div>

				<div class="layui-sub-form-item">
					<label class="input-label" for="is_del">状态：</label>
					
						<select  class="input" name="is_del" id="is_del">
							<option  value="0">启用</option>
							<option value="1">禁用</option>
						</select>
					</div>
				</div>
				<div class="layui-sub-form-item">
					<label class="input-label" for="remark" >备注：</label>
					<div class="input-block" >
						<textarea class="textarea" name="remark" rows="5"></textarea>
					</div>
				</div>
			</form>
		</div>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		layui.use('global', function() {
			var $ = layui.jquery;

			var active = {
				add : function() {
					winopen("{:url('UserFolder/add',array('controller'=>$controller,'has_pid'=>$has_pid))}", 560, 470);
				},

				del : function() {
					layer.msg('确定要删除吗?', {
						time : 0,
						btn : ['确定', '取消'],
						yes : function(index) {
							$("#opmode").val("del");
							var vars = $("#form_data").serialize();
							send_ajax("__SELF__", vars, function(ret) {
								if (ret.status) {
									layer.msg(ret.info, function() {
										location.reload(true);
									});
								}
							});
						},
						no : function(index) {
							layer.close(index);
						}
					});
				},
				save : function() {
					if ($("#opmode").val() == "") {
						layer.msg("请选择要修改的的数据");
						return false;
					}
					send_form("form_data", "", "__SELF__", function(e) {
						layer.msg(e.info);
					});
				},
			};
			$('.x-click').on('click', function() {
				var type = $(this).data('fun');
				active[type] ? active[type].call(this) : layer.msg("未定义操作");
			});

			function show_data(result) {
				for (var s in result.data) {
					set_val(s, result.data[s]);
				}
				$("#folder_name").val($("#folder_list option[value='" + $("#pid").val() + "']").text());
				$("#opmode").val("edit");
			}


			$(".sub-sidebar .tree_menu  a").click(function() {
				$(".sub-sidebar .tree_menu  a").each(function() {
					$(this).attr("class", "");
				});
				$(this).attr("class", "active");
				send_ajax("{:url('UserFolder/read')}", "id=" + $(this).attr("node"), function(data) {
					show_data(data);
				});
				return false;
			});
		});

	</script>
</block>